package com.lagou.controller;

import com.lagou.bean.ConsumerComponent;
import com.lagou.util.IPutils;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class HelloController {

    @Autowired
    private ConsumerComponent service;

    @RequestMapping("/hello")
    @ResponseBody
    public String sayHello(HttpServletRequest request){
        //获取客户端ip
        String clientIp = IPutils.getIpAddr(request);
        //往dubbo RpcContext中设置ip
        RpcContext.getContext().setAttachment("clientIP",clientIp);

        String result = service.sayHello("hello 你好", 1000);
        return "返回结果："+result;
    }


}
